<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Notice;
use App\Models\Renting;

class RentingController extends Controller
{
    public function update(Request $request)
    {
        # 用户id
        $id = $request->get("id");
        $data = $request->only([
            "truename",
            "phone",
            "email",
            "age",
            "card",
            "card_img"
        ]);
        Renting::where("id", $id)->update($data);
        // dump($data);
        // echo 11;die;
        return ["status" => 0, "msg" => "修改成功", "data" => $data];
    }
    public function show(Renting $renting)
    {
        return ["status" => 0, "msg" => "获取成功", "data" => $renting];
    }
    public function upfile(Request $request)
    {
        //        dump($request);die;
        # 如果没有给一个默认的图片
        $pic = "uploads/noimg.jpg";
        # 获取上传的节点
        $upName = $request->get("node", "article");
        # 判断他是否上传图片
        if ($request->hasFile("file")) {
            $file = $request->file("file");
            $filename = $file->store($upName, "upfile");
            $pic = "/uploads/" . $filename;
        }
        return ["pic" => $pic];
    }
    # 看房通知
    public function notice(Request $request){
        # 获取到用户id
        $id = $request->get("renting_id");
        $data = Notice::with("owner")->where("renting_id",$id)->paginate(config("app.pagsize"));
        // dump($data);die;
        return ["status" => 0,"msg" => "获取成功","data" => $data];
    }
}
